<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>缓存全局变量</title>
</head>
<body>
  <input type="button" value="button" id="btn1">
  <input type="button" value="button" id="btn2">
  <input type="button" value="button" id="btn3">
  <p>111</p>
  <input type="button" value="button" id="btn4">
  <input type="button" value="button" id="btn5">
  <p>222</p>
  <input type="button" value="button" id="btn6">
  <input type="button" value="button" id="btn7">
  <p>333</p>
  <input type="button" value="button" id="btn8">
  <input type="button" value="button" id="btn9">

  <script>
    function getBtn1 () {
      var btn1 = document.getElementById('btn1')
      var btn3 = document.getElementById('btn3')
      var btn5 = document.getElementById('btn5')
      var btn6 = document.getElementById('btn6')
      var btn9 = document.getElementById('btn9')
    }

    // 将全局
    function getBtn2 () {
      var documentObj = document
      var btn1 = documentObj.getElementById('btn1')
      var btn3 = documentObj.getElementById('btn3')
      var btn5 = documentObj.getElementById('btn5')
      var btn6 = documentObj.getElementById('btn6')
      var btn9 = documentObj.getElementById('btn9')
    }
  </script>
</body>
</html>
